Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Drawing.Imaging
Imports System.Drawing.drawing2d
Imports System.Text
Imports Lesnikowski.Barcode

'***********************************
'Object to handle all print commands
'***********************************

'********************************
'Finishing Document Fields
'********************************
'PlantLotNum    = OIBT.U_LotN0
'CustLotNum     = OWOR.U_CutLotNo
'CustCode       = OWOR.CardCode
'CustStyle      = OIBT.U_CustStyle
'To Be D&R      = OIBT.U_ToBeDR
'Special Order  = OIBT.U_SpecialOrder
'Repack Order   = OIBT.U_RepackOrder
'Care           = OIBT.U_Carrier
'Shade          = OIBT.U_ShadeSt
'Fiber Code     = OIBT.U_FiberCode
'Grade          = OIBT.U_Grade
'Pieces         = OIBT.U_Pieces
'Date Packed    = OIBT.U_DatePacked
'Item Name      = OIBT.ItemName
'Construction   = OIBT.U_Contruction
'Fiber Content  = OIBT.U_FiberCont
'Finished Width = OIBT.U_FinWidth
'Finish Desc.   = OWOR.U_FinishMix
'Putup          = OWOR.U_PutUpDes
'Markings       = OWOR.U_SpecialMarkings
'Total Yards    = ?
'Customer Patt. = OWOR.ItemName
'CC             = OIBT.U_CC
'Print Pattern  = ?
'CC Number      = OIBT.U_CC
'Color Code     = OIBT.U_ColorCode
'Color Name     = OIBT.U_ColorName
'Gross Weight   = OIBT.U_Grossw
'Tare Weight    = OIBT.u_Tarew
'Net Weight     = OIBT.U_Netweight

'***********************************
'Barcode Label Fields
'***********************************
'Plant Lot Num
'Cust Lot Num       
'Customer Code
'To Be D&R
'Special Order
'Repack Order
'Grade
'Date Packed
'Fabric Name
'Fiber Content
'Fiber Code
'Shade
'Finished Width
'Print Pattern = ?
'CC
'Color Code 
'Color Name
'Customer Name
'Total Yards
'Gross Weight
'Net Weight
'Attention
'Lot Number
'Bar Code


Friend Class Printer

    Private WithEvents BCL As New PrintDocument
    Private WithEvents FinDoc As New PrintDocument
    Private TH As New TextHandler
    Private m_DS As New DataSet

    Private Property DS() As DataSet
        Get
            Return m_DS
        End Get
        Set(ByVal value As DataSet)
            m_DS = value
        End Set
    End Property

    Friend Sub PrintBarcodeLabel(ByRef Printer As String, ByRef valDS As DataSet)

        'Create a local reference to the dataset
        DS = valDS

        'Set Windows default printer
        Dim WshNetwork As New Object
        WshNetwork = Microsoft.VisualBasic.CreateObject("WScript.Network")
        WshNetwork.SetDefaultPrinter(Printer)

        'Create Barcode Image and Save as a .Gif
        Dim Base As BaseBarcode
        Dim Img As String = CurDir() & "\LastBarcode.gif"
        Base = BarcodeFactory.GetBarcode(Symbology.Code39)
        Base.Number = DS.Tables(0).Rows(0).Item("BatchNum").ToString
        Base.ChecksumAdd = False
        Base.Height = 135
        Base.FontName = "Generic Monotype"
        Base.ForeColor = Color.Black
        Base.Save(Img, System.Drawing.Imaging.ImageFormat.Gif)

        'Create a gif file to use in the barcode label as an image to maximize the font size and space used
        Dim BatchNumImgPath As String = CurDir() & "/batchnum.gif"
        Dim OutputBitmap As New Bitmap(575, 185)
        Dim DrawGraphic = Graphics.FromImage(OutputBitmap)
        DrawGraphic.Clear(Color.White)
        DrawGraphic.SmoothingMode = SmoothingMode.AntiAlias
        Dim Str As String = DS.Tables(0).Rows(0).Item("BatchNum").ToString
        DrawGraphic.DrawString(Str, _
            New Font("Bodoni MT Condensed", 163, FontStyle.Bold), _
            Brushes.Black, New PointF(-47, -40))
        OutputBitmap.Save(BatchNumImgPath, ImageFormat.Gif)

        Dim WD As New WordDoc
        WD.PrintBarcodeLabel(DS, Img, BatchNumImgPath)

    End Sub

    Friend Sub PrintFinishingDoc(ByRef Printer As String, ByRef valDS As DataSet)

        DS = valDS
        FinDoc.PrinterSettings.PrinterName = Printer
        FinDoc.DocumentName = "Finishing Document"
        FinDoc.Print()

    End Sub

    Private Sub PrintFinishing(ByVal Sender As System.Object, _
        ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles FinDoc.PrintPage

        If TH Is Nothing Then
            TH = New TextHandler
        End If

        'Define static strings
        '********************************************************
        'Create ATTENTION string
        Dim Att As String = "ATTENTION"
        'Disclaimer
        Dim Disc1 As String = "Goods in this carton must be cut seperate from other cartons or must be cut with goods of the same"
        Dim Disc2 As String = "shade letter marking from the same lot number.  This fabric may contain and may release a low level"
        Dim Disc3 As String = "of formaldehyde."

        '********************************************************

        'Define x and y marinbounds for the printer.
        Dim x As Integer = e.MarginBounds.X, y As Integer = e.MarginBounds.Y

        Dim V8 As New Font("Generic Monotype", 8, FontStyle.Regular, GraphicsUnit.Pixel)
        Dim V9 As New Font("Generic Monotype", 9, FontStyle.Regular, GraphicsUnit.Pixel)
        Dim V12_bold As New Font("Generic Monotype", 12, FontStyle.Bold, GraphicsUnit.Pixel)

        Dim V20_bold As New Font("Generic Monotype", 20, FontStyle.Bold, _
            GraphicsUnit.Pixel)

        Dim BoldPen As New Pen(Color.Black, 3)
        Dim DashPen As New Pen(Color.Black, 1)
        DashPen.DashStyle = Drawing2D.DashStyle.DashDotDot
        DashPen.Color = Color.Gray

        Dim LineHt As Integer = V9.Height * 2
        Dim yStartPos As Integer
        Dim i As Integer

        'Draw boundry rectangle
        e.Graphics.DrawRectangle(Pens.Black, e.MarginBounds)
        'Draw midway dashed line in gray
        e.Graphics.DrawLine(DashPen, e.MarginBounds.Left, 550, e.MarginBounds.Right, 550)

        Dim l As Integer
        For l = 0 To 1

            'yStartPos = the location of the line below the "Goods in the carton..." line.  It is used as a
            'starting point to create nine boxes of identical height.            
            If l = 0 Then
                yStartPos = (e.MarginBounds.Top)
            Else
                yStartPos = (e.MarginBounds.Bottom - 250 - (LineHt * 8))
                'draw top line
                e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left, yStartPos, e.MarginBounds.Right, yStartPos)
            End If

            'Draw horizontal lines for top of page

            For i = 1 To 9
                e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left, (yStartPos + (LineHt * i)), e.MarginBounds.Right, (yStartPos + (LineHt * i)))
            Next

            'Draw verticle lines and text   
            '***************************************************************************************************************

            ')))))))))))))))))))))))))
            'Line 1
            '((((((((((((((((((((((((
            'Plant Lot No.
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 60, yStartPos, e.MarginBounds.Left + 60, yStartPos + LineHt)
            e.Graphics.DrawString("Plant Lot No.", V8, Brushes.Gray, e.MarginBounds.Left, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_LotN0").ToString, 12), V9, Brushes.Black, e.MarginBounds.Left, yStartPos + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("A23456789011234", 12), V9, Brushes.Black, e.MarginBounds.Left, yStartPos + V8.Height)

            'Cust Lot No.
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 130, yStartPos, e.MarginBounds.Left + 130, yStartPos + LineHt)
            e.Graphics.DrawString("Customer Lot No.", V8, Brushes.Gray, e.MarginBounds.Left + 61, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_CustLotNo").ToString, 15), V9, Brushes.Black, e.MarginBounds.Left + 61, yStartPos + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("asdfasdfAOOIULLKJPOIJN", 15), V9, Brushes.Black, e.MarginBounds.Left + 61, yStartPos + V8.Height)

            'Cust Code
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 170, yStartPos, e.MarginBounds.Left + 170, yStartPos + LineHt)
            e.Graphics.DrawString("Cust Code", V8, Brushes.Gray, e.MarginBounds.Left + 131, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("CardCode").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 131, yStartPos + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("dsalsdlkjfkjlsajklfIAIOSDF", 10), V9, Brushes.Black, e.MarginBounds.Left + 131, yStartPos + V8.Height)

            'Cust Style
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 220, yStartPos, e.MarginBounds.Left + 220, yStartPos + LineHt)
            e.Graphics.DrawString("Cust Style", V8, Brushes.Gray, e.MarginBounds.Left + 171, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_CustStyle").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 171, yStartPos + V8.Height)

            'To Be DR
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 270, yStartPos, e.MarginBounds.Left + 270, yStartPos + LineHt)
            e.Graphics.DrawString("To Be DR", V8, Brushes.Gray, e.MarginBounds.Left + 221, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_ToBeDR").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 221, yStartPos + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("120938asdljkdsfDSslll", 10), V9, Brushes.Black, e.MarginBounds.Left + 221, yStartPos + V8.Height)

            'Special Order
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 320, yStartPos, e.MarginBounds.Left + 320, yStartPos + LineHt)
            e.Graphics.DrawString("Special Order", V8, Brushes.Gray, e.MarginBounds.Left + 271, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_SpecialOrder").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 271, yStartPos + V8.Height)

            'Repack Order
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 370, yStartPos, e.MarginBounds.Left + 370, yStartPos + LineHt)
            e.Graphics.DrawString("Repack", V8, Brushes.Gray, e.MarginBounds.Left + 321, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength("1A3DSSI123ASDLK;JF", 10), V9, Brushes.Black, e.MarginBounds.Left + 321, yStartPos + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_RepackOrder").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 321, yStartPos + V8.Height)

            'Care
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 420, yStartPos, e.MarginBounds.Left + 420, yStartPos + LineHt)
            e.Graphics.DrawString("Care", V8, Brushes.Gray, e.MarginBounds.Left + 371, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_Carrier").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 371, yStartPos + V8.Height)

            'Shade
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 470, yStartPos, e.MarginBounds.Left + 470, yStartPos + LineHt)
            e.Graphics.DrawString("Shade", V8, Brushes.Gray, e.MarginBounds.Left + 421, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_ShadeSt").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 421, yStartPos + V8.Height)

            'Fiber Code
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 520, yStartPos, e.MarginBounds.Left + 520, yStartPos + LineHt)
            e.Graphics.DrawString("Fiber Code", V8, Brushes.Gray, e.MarginBounds.Left + 471, yStartPos)
            e.Graphics.DrawString(DS.Tables(0).Rows(0).Item("U_FiberCode").ToString, V9, Brushes.Black, e.MarginBounds.Left + 471, yStartPos + V8.Height)

            'Grade
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 560, yStartPos, e.MarginBounds.Left + 560, yStartPos + LineHt)
            e.Graphics.DrawString("Grade", V8, Brushes.Gray, e.MarginBounds.Left + 521, yStartPos)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_Grade").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 521, yStartPos + V8.Height)

            'Pieces
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 600, yStartPos, e.MarginBounds.Left + 600, yStartPos + LineHt)
            e.Graphics.DrawString("Pieces", V8, Brushes.Gray, e.MarginBounds.Left + 561, yStartPos)
            e.Graphics.DrawString(DS.Tables(0).Rows(0).Item("U_Pieces").ToString, V9, Brushes.Black, e.MarginBounds.Left + 561, yStartPos + V8.Height)

            'Date Packed
            Dim DP As String
            DP = DS.Tables(0).Rows(0).Item("U_Datepacked").ToString
            If Not DS.Tables(0).Rows(0).Item("U_Datepacked") Is DBNull.Value Then
                DP = CDate(DS.Tables(0).Rows(0).Item("U_Datepacked").ToString).ToShortDateString
            Else
                DP = ""
            End If
            e.Graphics.DrawString("Pack Date", V8, Brushes.Gray, e.MarginBounds.Left + 601, yStartPos)
            e.Graphics.DrawString(DP.ToString, V8, Brushes.Black, e.MarginBounds.Left + 601, yStartPos + V8.Height)

            ')))))))))))))))))))))))))
            'Line 2
            '((((((((((((((((((((((((

            'Fabric Name
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 170, (yStartPos + LineHt), e.MarginBounds.Left + 170, (yStartPos + (LineHt * 2)))
            e.Graphics.DrawString("Fabric Name", V8, Brushes.Gray, e.MarginBounds.Left + 1, yStartPos + LineHt)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_FabricName").ToString), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + LineHt) + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("asdkjflskjdlfkjsdlkfjweoi120398asdfasdfI12038120983asldflkdjf", 31), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + LineHt) + V8.Height)

            'Construction
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 320, (yStartPos + LineHt), e.MarginBounds.Left + 320, (yStartPos + (LineHt * 2)))
            e.Graphics.DrawString("Construction", V8, Brushes.Gray, e.MarginBounds.Left + 171, yStartPos + LineHt)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_Construction").ToString), V9, Brushes.Black, e.MarginBounds.Left + 171, (yStartPos + LineHt) + V8.Height)

            'Fiber Content
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 470, (yStartPos + LineHt), e.MarginBounds.Left + 470, (yStartPos + (LineHt * 2)))
            e.Graphics.DrawString("Fiber Content", V8, Brushes.Gray, e.MarginBounds.Left + 321, yStartPos + LineHt)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_FiberCont").ToString), V9, Brushes.Black, e.MarginBounds.Left + 321, (yStartPos + LineHt) + V8.Height)

            'Finished Width
            e.Graphics.DrawString("Finished Width", V8, Brushes.Gray, e.MarginBounds.Left + 471, yStartPos + LineHt)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_FinWidth").ToString), V9, Brushes.Black, e.MarginBounds.Left + 471, (yStartPos + LineHt) + V8.Height)

            ')))))))))))))))))))))))))
            'Line 3
            '((((((((((((((((((((((((

            'Finish Desc
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 220, (yStartPos + (LineHt * 2)), e.MarginBounds.Left + 220, (yStartPos + (LineHt * 3)))
            e.Graphics.DrawString("Finish Description", V8, Brushes.Gray, e.MarginBounds.Left + 1, yStartPos + (LineHt * 2))
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_FinishDesc").ToString, 41), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + (LineHt * 2) + V8.Height))
            'e.Graphics.DrawString(TH.TrimStringLength("asdlfja;lskjdflkjas;ldkjfowieuiweuouiweoiuwelkjsdjklsdjklfdsklsdnfdsjhsdfhsdfkjdsfkjdsfkjdsfkfsdj", 40), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + (LineHt * 2) + V8.Height))

            'Putup
            If DS.Tables(1).Rows.Count > 0 Then
                e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 370, (yStartPos + (LineHt * 2)), e.MarginBounds.Left + 370, (yStartPos + (LineHt * 3)))
                e.Graphics.DrawString("Putup", V8, Brushes.Gray, e.MarginBounds.Left + 221, yStartPos + (LineHt * 2))
                e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(1).Rows(0).Item("U_PutupDes").ToString, 27), V9, Brushes.Black, e.MarginBounds.Left + 221, (yStartPos + (LineHt * 2)) + V8.Height)
                'e.Graphics.DrawString(TH.TrimStringLength("asdflkjsdlkjflksjdfwoiefoiujweoifjwoeijewoijewfoijwef", 27), V9, Brushes.Black, e.MarginBounds.Left + 221, (yStartPos + (LineHt * 2)) + V8.Height)
            End If

            'Markings
            If DS.Tables(1).Rows.Count > 0 Then
                e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 520, (yStartPos + (LineHt * 2)), e.MarginBounds.Left + 520, (yStartPos + (LineHt * 3)))
                e.Graphics.DrawString("Markings", V8, Brushes.Gray, e.MarginBounds.Left + 371, yStartPos + (LineHt * 2))
                'Changed u_specialmarkings to u_markings on 4/9/07
                e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(1).Rows(0).Item("U_Markings").ToString, 27), V9, Brushes.Black, e.MarginBounds.Left + 371, (yStartPos + (LineHt * 2)) + V8.Height)
            End If

            'Total Yards
            e.Graphics.DrawString("Total Yards", V8, Brushes.Gray, e.MarginBounds.Left + 521, yStartPos + (LineHt * 2))
            'Changed U_TotalQty to U_RecQty for new version
            '04/09/07
            'e.Graphics.DrawString(TH.RoundToOneDec(DS.Tables(0).Rows(0).Item("U_TotalQty")).ToString, V9, Brushes.Black, e.MarginBounds.Left + 521, (yStartPos + (LineHt * 2)) + V8.Height)
            e.Graphics.DrawString(TH.RoundToOneDec(DS.Tables(0).Rows(0).Item("U_RecQty")).ToString, V9, Brushes.Black, e.MarginBounds.Left + 521, (yStartPos + (LineHt * 2)) + V8.Height)

            ')))))))))))))))))))))))))
            'Line 4
            '((((((((((((((((((((((((

            'Customer Pattern
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 95, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 95, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Cust Pattern", V8, Brushes.Gray, e.MarginBounds.Left + 1, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_CustomerPat").ToString, 17), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + (LineHt * 3) + V8.Height))
            'e.Graphics.DrawString(TH.TrimStringLength("as;lkdjfkjowowfoinfeoinwoinwfeoinwe", 17), V9, Brushes.Black, e.MarginBounds.Left + 1, (yStartPos + (LineHt * 3) + V8.Height))

            'Cust. CC
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 145, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 145, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Cust CC", V8, Brushes.Gray, e.MarginBounds.Left + 96, yStartPos + (LineHt * 3) + 1)
            'e.Graphics.DrawString("Cust CC", V8, Brushes.Gray, e.MarginBounds.Left + 96, yStartPos + (LineHt * 3) + 1)
            'e.Graphics.DrawString("", V9, Brushes.Black, e.MarginBounds.Left + 96, (yStartPos + (LineHt * 3)) + V8.Height)

            'Print Pattern
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 220, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 220, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Print Pattern", V8, Brushes.Gray, e.MarginBounds.Left + 146, yStartPos + (LineHt * 3) + 1)
            'Changed Item to "U_PrintPat" from "65" on 4/9/07
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_PrintPat").ToString, 14), V9, Brushes.Black, e.MarginBounds.Left + 146, (yStartPos + (LineHt * 3)) + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("asldkjflkjsdoijfowienfowinfoiewfoaisdoif", 14), V9, Brushes.Black, e.MarginBounds.Left + 146, (yStartPos + (LineHt * 3)) + V8.Height)

            'CC NO
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 270, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 270, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("C.C. No.", V8, Brushes.Gray, e.MarginBounds.Left + 221, yStartPos + (LineHt * 3) + 1)
            'e.Graphics.DrawString(TH.TrimStringLength("asldjfljsldkjflskdjflskjdflskjdf", 10), V9, Brushes.Black, e.MarginBounds.Left + 221, (yStartPos + (LineHt * 3)) + V8.Height)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_CC").ToString, 10), V9, Brushes.Black, e.MarginBounds.Left + 221, (yStartPos + (LineHt * 3)) + V8.Height)

            'Color Code
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 345, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 345, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Color Code", V8, Brushes.Gray, e.MarginBounds.Left + 271, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_ColorCode").ToString, 14), V9, Brushes.Black, e.MarginBounds.Left + 271, (yStartPos + (LineHt * 3)) + V8.Height)

            'Color Name
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 470, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 470, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Color Name", V8, Brushes.Gray, e.MarginBounds.Left + 346, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(TH.TrimStringLength(DS.Tables(0).Rows(0).Item("U_ColorName").ToString, 21), V9, Brushes.Black, e.MarginBounds.Left + 346, (yStartPos + (LineHt * 3)) + V8.Height)
            'e.Graphics.DrawString(TH.TrimStringLength("sdhwoiuweoiuwehiosdhsadfjsadfkasdfkjsdfksdfkjdsf", 21), V9, Brushes.Black, e.MarginBounds.Left + 346, (yStartPos + (LineHt * 3)) + V8.Height)

            'Gross Weight
            Dim GW As Double = 0
            If Not DS.Tables(0).Rows(0).Item("U_Grossw") Is DBNull.Value Then
                GW = TH.RoundToOneDec(DS.Tables(0).Rows(0).Item("U_Grossw")).ToString
            End If
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 525, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 525, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Gross Wt", V8, Brushes.Gray, e.MarginBounds.Left + 471, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(GW, V9, Brushes.Black, e.MarginBounds.Left + 471, (yStartPos + (LineHt * 3)) + V8.Height)

            'Tare Weight
            Dim TW As Double = 0
            If Not DS.Tables(0).Rows(0).Item("u_Tarew") Is DBNull.Value Then
                TW = TH.RoundToOneDec(DS.Tables(0).Rows(0).Item("u_Tarew")).ToString
            End If
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 580, (yStartPos + (LineHt * 3)), e.MarginBounds.Left + 580, (yStartPos + (LineHt * 4)))
            e.Graphics.DrawString("Tare Wt", V8, Brushes.Gray, e.MarginBounds.Left + 526, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(TW, V9, Brushes.Black, e.MarginBounds.Left + 526, (yStartPos + (LineHt * 3)) + V8.Height)

            'Net Weight
            Dim NW As Double = 0
            If Not DS.Tables(0).Rows(0).Item("U_Netweight") Is DBNull.Value Then
                NW = TH.RoundToOneDec(DS.Tables(0).Rows(0).Item("U_Netweight")).ToString
            End If
            e.Graphics.DrawString("Net Wt", V8, Brushes.Gray, e.MarginBounds.Left + 581, yStartPos + (LineHt * 3) + 1)
            e.Graphics.DrawString(NW, V9, Brushes.Black, e.MarginBounds.Left + 581, (yStartPos + (LineHt * 3)) + V8.Height)

            ')))))))))))))))))))))))))
            'Sub-batches
            '((((((((((((((((((((((((
            'vertical lines

            'PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
            'dark vertical lines

            e.Graphics.DrawLine(BoldPen, e.MarginBounds.Left + 162, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 162, (yStartPos + (LineHt * 9)))
            'e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 163, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 163, (yStartPos + (LineHt * 9)))

            e.Graphics.DrawLine(BoldPen, e.MarginBounds.Left + 324, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 324, (yStartPos + (LineHt * 9)))
            'e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 325, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 325, (yStartPos + (LineHt * 9)))

            e.Graphics.DrawLine(BoldPen, e.MarginBounds.Left + 486, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 486, (yStartPos + (LineHt * 9)))
            'e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 487, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 487, (yStartPos + (LineHt * 9)))

            'vertical lines for text items
            'Roll Num
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 45, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 45, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Roll Num", V8, Brushes.Gray, e.MarginBounds.Left + 1, yStartPos + (LineHt * 4) + 1)

            'Insp.
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 70, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 70, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Insp.", V8, Brushes.Gray, e.MarginBounds.Left + 46, yStartPos + (LineHt * 4) + 1)

            'CA CD
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 95, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 95, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("CACD", V8, Brushes.Gray, e.MarginBounds.Left + 70, yStartPos + (LineHt * 4) + 1)

            'Yards
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 130, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 130, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Yards", V8, Brushes.Gray, e.MarginBounds.Left + 96, yStartPos + (LineHt * 4) + 1)

            'Eigths
            e.Graphics.DrawString("Eigths", V8, Brushes.Gray, e.MarginBounds.Left + 131, yStartPos + (LineHt * 4) + 1)

            'vertical lines for text items (2nd set)
            '************************************************************
            'Roll Num
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 207, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 207, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Roll Num", V8, Brushes.Gray, e.MarginBounds.Left + 165, yStartPos + (LineHt * 4) + 1)

            'Insp.
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 232, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 232, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Insp.", V8, Brushes.Gray, e.MarginBounds.Left + 208, yStartPos + (LineHt * 4) + 1)

            'CA CD
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 257, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 257, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("CACD", V8, Brushes.Gray, e.MarginBounds.Left + 231, yStartPos + (LineHt * 4) + 1)

            'Yards
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 292, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 292, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Yards", V8, Brushes.Gray, e.MarginBounds.Left + 258, yStartPos + (LineHt * 4) + 1)

            'Eigths
            e.Graphics.DrawString("Eigths", V8, Brushes.Gray, e.MarginBounds.Left + 293, yStartPos + (LineHt * 4) + 1)

            'vertical lines for text items (3rd set)
            'Roll Num
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 369, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 369, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Roll Num", V8, Brushes.Gray, e.MarginBounds.Left + 326, yStartPos + (LineHt * 4) + 1)

            'Inps.
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 394, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 394, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Insp.", V8, Brushes.Gray, e.MarginBounds.Left + 370, yStartPos + (LineHt * 4) + 1)

            'CA CD
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 419, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 419, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("CACD", V8, Brushes.Gray, e.MarginBounds.Left + 394, yStartPos + (LineHt * 4) + 1)

            'Yards
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 454, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 454, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Yards", V8, Brushes.Gray, e.MarginBounds.Left + 420, yStartPos + (LineHt * 4) + 1)

            'Eigths
            e.Graphics.DrawString("Eigths", V8, Brushes.Gray, e.MarginBounds.Left + 455, yStartPos + (LineHt * 4) + 1)

            'vertical lines for text items (4th set)
            'Roll Num
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 531, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 531, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Roll Num", V8, Brushes.Gray, e.MarginBounds.Left + 488, yStartPos + (LineHt * 4) + 1)

            'Insp
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 556, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 556, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Insp.", V8, Brushes.Gray, e.MarginBounds.Left + 532, yStartPos + (LineHt * 4) + 1)

            'CACD
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 581, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 581, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("CACD", V8, Brushes.Gray, e.MarginBounds.Left + 556, yStartPos + (LineHt * 4) + 1)

            'yards
            e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left + 616, (yStartPos + (LineHt * 4)), e.MarginBounds.Left + 616, (yStartPos + (LineHt * 9)))
            e.Graphics.DrawString("Yards", V8, Brushes.Gray, e.MarginBounds.Left + 582, yStartPos + (LineHt * 4) + 1)

            'Eigths
            e.Graphics.DrawString("Eigths", V8, Brushes.Gray, e.MarginBounds.Left + 617, yStartPos + (LineHt * 4) + 1)
            'PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

            'Put data in sub batch detail
            Dim RollNum As String, Insp As String, CACD As String, Yards As String, Eigths As String
            Dim SubY As Integer

            'First set of 5 rows
            Try
                Dim C As Integer
                For C = 0 To 4
                    SubY = yStartPos + (((LineHt * (4 + C)) + V8.Height + 1))
                    RollNum = DS.Tables(2).Rows(C).Item("RollNum").ToString
                    Insp = DS.Tables(2).Rows(C).Item("Insp").ToString
                    CACD = DS.Tables(2).Rows(C).Item("CACD").ToString
                    Yards = TH.RoundToOneDec(DS.Tables(2).Rows(C).Item("Yards")).ToString
                    Eigths = DS.Tables(2).Rows(C).Item("Eigths").ToString

                    e.Graphics.DrawString(RollNum, V8, Brushes.Black, e.MarginBounds.Left + 1, SubY)
                    e.Graphics.DrawString(Insp, V8, Brushes.Black, e.MarginBounds.Left + 46, SubY)
                    e.Graphics.DrawString(CACD, V8, Brushes.Black, e.MarginBounds.Left + 71, SubY)
                    e.Graphics.DrawString(Yards, V8, Brushes.Black, e.MarginBounds.Left + 96, SubY)
                    e.Graphics.DrawString(Eigths, V8, Brushes.Black, e.MarginBounds.Left + 131, SubY)
                Next
            Catch ex As Exception
                'Ignore overflow errors
            End Try

            '2nd set of 5 rows
            Try
                Dim C As Integer
                For C = 0 To 4
                    SubY = yStartPos + (((LineHt * (4 + C)) + V8.Height + 1))
                    RollNum = DS.Tables(2).Rows(C + 5).Item(3).ToString
                    Insp = DS.Tables(2).Rows(C + 5).Item(5).ToString
                    CACD = DS.Tables(2).Rows(C + 5).Item(6).ToString
                    Yards = TH.RoundToOneDec(DS.Tables(2).Rows(C + 5).Item(4).ToString)
                    Eigths = DS.Tables(2).Rows(C + 5).Item(7).ToString

                    e.Graphics.DrawString(RollNum, V8, Brushes.Black, e.MarginBounds.Left + 163, SubY)
                    e.Graphics.DrawString(Insp, V8, Brushes.Black, e.MarginBounds.Left + 208, SubY)
                    e.Graphics.DrawString(CACD, V8, Brushes.Black, e.MarginBounds.Left + 233, SubY)
                    e.Graphics.DrawString(Yards, V8, Brushes.Black, e.MarginBounds.Left + 258, SubY)
                    e.Graphics.DrawString(Eigths, V8, Brushes.Black, e.MarginBounds.Left + 292, SubY)
                Next
            Catch ex As Exception
                'Ignore overflow errors
            End Try

            '3rd set of 5 rows
            Try
                Dim C As Integer
                For C = 0 To 4
                    SubY = yStartPos + (((LineHt * (4 + C)) + V8.Height + 1))
                    RollNum = DS.Tables(2).Rows(C + 10).Item(3).ToString
                    Insp = DS.Tables(2).Rows(C + 10).Item(5).ToString
                    CACD = DS.Tables(2).Rows(C + 10).Item(6).ToString
                    Yards = TH.RoundToOneDec(DS.Tables(2).Rows(C + 10).Item(4)).ToString
                    Eigths = DS.Tables(2).Rows(C + 10).Item(7).ToString

                    e.Graphics.DrawString(RollNum, V8, Brushes.Black, e.MarginBounds.Left + 325, SubY)
                    e.Graphics.DrawString(Insp, V8, Brushes.Black, e.MarginBounds.Left + 370, SubY)
                    e.Graphics.DrawString(CACD, V8, Brushes.Black, e.MarginBounds.Left + 395, SubY)
                    e.Graphics.DrawString(Yards, V8, Brushes.Black, e.MarginBounds.Left + 420, SubY)
                    e.Graphics.DrawString(Eigths, V8, Brushes.Black, e.MarginBounds.Left + 455, SubY)
                Next
            Catch ex As Exception
                'Ignore overflow errors
            End Try

            '4th set of 5 rows
            Try
                Dim C As Integer
                For C = 0 To 4
                    SubY = yStartPos + (((LineHt * (4 + C)) + V8.Height + 1))
                    RollNum = DS.Tables(2).Rows(C + 15).Item(3).ToString
                    Insp = DS.Tables(2).Rows(C + 15).Item(5).ToString
                    CACD = DS.Tables(2).Rows(C + 15).Item(6).ToString
                    Yards = TH.RoundToOneDec(DS.Tables(2).Rows(C + 15).Item(4)).ToString
                    Eigths = DS.Tables(2).Rows(C + 15).Item(7).ToString

                    e.Graphics.DrawString(RollNum, V8, Brushes.Black, e.MarginBounds.Left + 487, SubY)
                    e.Graphics.DrawString(Insp, V8, Brushes.Black, e.MarginBounds.Left + 532, SubY)
                    e.Graphics.DrawString(CACD, V8, Brushes.Black, e.MarginBounds.Left + 557, SubY)
                    e.Graphics.DrawString(Yards, V8, Brushes.Black, e.MarginBounds.Left + 582, SubY)
                    e.Graphics.DrawString(Eigths, V8, Brushes.Black, e.MarginBounds.Left + 617, SubY)
                Next
            Catch ex As Exception
                'Ignore overflow errors
            End Try

            'Customer Name (Large)
            e.Graphics.DrawString("Customer Name:", V9, Brushes.Black, e.MarginBounds.Left + 162, (yStartPos + (LineHt * 10)))
            e.Graphics.DrawString(DS.Tables(0).Rows(0).Item("U_CustName").ToString, V20_bold, Brushes.Black, e.MarginBounds.Left + 247, (yStartPos + (LineHt * 10) - 7))

            'Quality Description
            Dim Grade As String = ""

            Select Case DS.Tables(0).Rows(0).Item("U_Grade").ToString

                Case 1
                    Grade = "First Quality"

                Case 2
                    Grade = "Second Quality"

                Case 3
                    Grade = "Second Greige Mill"

                Case 4
                    Grade = "Damaged"

                Case Else
                    Grade = "Quality Not Available"

            End Select

            e.Graphics.DrawString(Grade, V12_bold, Brushes.Black, e.MarginBounds.Left + 250, yStartPos + (LineHt * 11))

            'Barcode Repeat
            'e.Graphics.DrawString(DS.Tables(0).Rows(0).Item(37).ToString, V20_bold, Brushes.Black, (e.MarginBounds.Left + 162), (yStartPos + (LineHt * 16)))

            Dim Base As BaseBarcode
            Base = BarcodeFactory.GetBarcode(Symbology.Code39)
            Base.Number = DS.Tables(0).Rows(0).Item("BatchNum").ToString
            Base.ChecksumAdd = False
            Base.Height = 200
            Base.FontName = "verdana"
            Base.ForeColor = Color.Black
            Base.Render(e.Graphics, 600, (yStartPos + (LineHt * 10) - 7))

            e.Graphics.DrawString(Att, V12_bold, Brushes.Gray, e.MarginBounds.Left + 10, (yStartPos + (LineHt * 13)))
            e.Graphics.DrawString(Disc1, V9, Brushes.Gray, e.MarginBounds.Left + 10, (yStartPos + (LineHt * 13) + V9.Height))
            e.Graphics.DrawString(Disc2, V9, Brushes.Gray, e.MarginBounds.Left + 10, (yStartPos + (LineHt * 13) + (V9.Height * 2)))
            e.Graphics.DrawString(Disc3, V9, Brushes.Gray, e.MarginBounds.Left + 10, (yStartPos + (LineHt * 13) + (V9.Height * 3)))

        Next

        '***************************************************************************************************************

    End Sub


End Class
